<script setup lang="ts">
  import { HMessageBox } from '@/components/common/message'
  import { useAllotInWarehouseSign } from '@/services/pages/storage/useWarehouse'
  import { PropType } from 'vue'

  const { signForm, signLoading, sign, resetForm } = useAllotInWarehouseSign()

  const props = defineProps({
    allotInWarehouseIdList: {
      type: Array as PropType<Array<string>>,
      required: true,
    },
  })

  const emits = defineEmits<{
    (e: 'update'): void
  }>()

  // 弹窗显示状态
  const visible = defineModel('modelValue', { type: Boolean, default: false })

  /**
   * 隐藏弹窗
   */
  const hideDialog = () => {
    resetForm()
    visible.value = false
  }

  /**
   * 确定事件
   */
  const onConfirm = async () => {
    signForm.value.ids = props.allotInWarehouseIdList
    const res = await sign()
    if (res.code === 20000) {
      emits('update')
      hideDialog()
      return
    }
    HMessageBox.error(res.message)
  }
</script>

<template>
  <h-dialog v-model="visible" title="调拨入库签收" :loading="signLoading" @close="hideDialog">
    <el-form :model="signForm" label-position="top" inline-message class="modal_form_content">
      <el-form-item label="签收备注" prop="remark">
        <el-input
          v-model="signForm.remark"
          type="textarea"
          maxlength="200"
          show-word-limit
          placeholder="请输入备注"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <h-button is-modal type="primary" @click="onConfirm">确定</h-button>
      <h-button is-modal @click="hideDialog">取消</h-button>
    </template>
  </h-dialog>
</template>

<style scoped lang="scss">
  :deep(.el-textarea__inner) {
    height: 100px;
  }
</style>
